package com.ruoyi.web.controller.api.patient;

import com.ruoyi.common.constant.HttpStatusCusCode;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.CustomizeDataInfo;
import com.ruoyi.system.domain.api.patient.PatientInfoDto;
import com.ruoyi.system.domain.api.patient.RelationshipDto;
import com.ruoyi.system.service.api.patient.IPatientApiService;
import com.ruoyi.system.service.api.patient.IRelationshipApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;


/**
 * 患者相关Controller
 *
 * @author sergio
 * @date 2024-11-15
 */
@Api(tags = "患者信息")
@RestController
@RequestMapping("/api/patient/patient")
public class PatientApiController extends BaseController {

    @Autowired
    private IPatientApiService patientApiService;
    /**
     * 获取医生绑定关系下的所有患者信息
     *
     * @author sergio
     * @date 2024/11/14
     */
    @ApiOperation("获取医生绑定关系下的所有患者信息")
    @PostMapping("/patientFollow")
    public CustomizeDataInfo followPatient(@RequestBody @Valid RelationshipDto relationshipDto)
    {
        if (relationshipDto != null &&
                relationshipDto.getDoctorInfo() != null &&
                relationshipDto.getDoctorInfo().getDoctorId() != null) {
            // 两者都不为空时的处理逻辑
            startPage();
            List<PatientInfoDto> patientInfoDtoList = patientApiService.getPatientInfoByDoctorId(relationshipDto);
            return getCustomizeDataTable(patientInfoDtoList);
        } else {
            // 任意一个为空时的处理逻辑
            CustomizeDataInfo errorResponse = new CustomizeDataInfo();
            errorResponse.setCode(HttpStatusCusCode.DOCTOR_ID_NOT_FOUND.getCode());
            errorResponse.setMsg(HttpStatusCusCode.DOCTOR_ID_NOT_FOUND.getMessage());
            return errorResponse;
        }

    }


}
